home *** CD-ROM | disk | FTP | other *** search
- Path: llnews.ll.mit.edu!usenet
- From: kappu@ll.mit.edu (Kalpana Subramanian)
- Newsgroups: comp.lang.c++,gnu.g++.help,gnu.g++
- Subject: g++ warning about initialization of non-const obj& - help needed
- Date: 31 Jan 1996 16:41:34 GMT
- Organization: MIT Lincoln Laboratory
- Distribution: world
- Message-ID: <4eo63u$kr1@llnews.ll.mit.edu>
- Originator: rachel@sun46a
-
- Hello g++ users,
-
- I have a function declared as such:
-
- func( obj &)
-
- I go to use it thus:
-
- func( obj.memberfunc() returning an obj);
-
- I get a warning -
-
- warning: initialization of non-const `obj &' from rvalue `obj'
-
- If I make a temporary obj, obj2 = obj.memberfunc()returning an obj,
- and call func(obj2), it compiles.
-
- In reading the FAQ, I understand that temporaries inside function calls
- that require conversion can get deleted before the conversion process,
- thus causing erroneous results and should be avoided. However, in this
- usage, the compiler should be able to make a reference from an object,
- shouldn't it? Is it that the compiler will only want to make a const
- reference from an object? The code I am compiling was all compiled under
- previous versions of g++, and I wanted to upgrade it all. I am using
- gcc/g++2.7.2 on a SunOS 4.1.4 platform.
-
- If this is obvious to anybody, could you please explain what the
- issue is?
-
- Thank you.
-
- Kalpana Subramanian
-